/*!
 * ---------------------------------------------------------------------
 *
 * GLPI - Gestionnaire Libre de Parc Informatique
 *
 * http://glpi-project.org
 *
 * @copyright 2015-2025 Teclib' and contributors.
 * @copyright 2003-2014 by the INDEPNET Development Team.
 * @licence   https://www.gnu.org/licenses/gpl-3.0.html
 *
 * ---------------------------------------------------------------------
 *
 * LICENSE
 *
 * This file is part of GLPI.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * ---------------------------------------------------------------------
 */

// Hide the dynamic input when the accordion is collapsed
// and show the name when the accordion is expanded
#glpi-destinations-accordion {
    > .accordion-item > .accordion-header > .accordion-button {
        &.collapsed {
            input.glpi-form-destination-name {
                display: none !important;
            }
        }

        &:not(.collapsed) {
            span.glpi-form-destination-name {
                display: none !important;
            }

            // Update vertical padding to match with the collapsed height state
            padding-top: 11px !important;
            padding-bottom: 11px !important;
        }
    }
}

[data-glpi-associated-items-specific-values-extra-field] {
    [data-glpi-associated-items-specific-values-extra-field-container] {
        [data-glpi-associated-items-specific-values-extra-field-item] {
            padding-left: 1px;

            >span:last-of-type {
                flex-grow: 1;

                .select2-container {
                    width: 100% !important;
                }
            }

            &:last-of-type {
                [data-glpi-remove-associated-item-button] {
                    border-bottom-right-radius: var(--tblr-btn-border-radius) !important;
                }
            }

            &:not(:has([data-glpi-associated-items-items-id-dropdown])) {
                .select2-container {
                    width: 100% !important;
                }
            }
        }

        .input-group[data-glpi-associated-items-specific-values-extra-field-item] {
            >span:first-of-type {
                .select2-selection {
                    border-top-right-radius: 0 !important;
                    border-bottom-right-radius: 0 !important;
                }
            }

            >span:not(:first-of-type) {
                .select2-selection {
                    border-radius: 0 !important;
                }
            }
        }
    }

    [data-glpi-add-associated-item-button] {
        position: relative;
        margin-left: 1px;
        margin-top: calc(-1 * var(--tblr-border-width));
        border-top-left-radius: 0 !important;
        border-top-right-radius: 0 !important;
    }
}

[data-glpi-itildestination-field-configs] {
    &:not(:has(> [data-glpi-itildestination-field-config]:nth-child(2))) {
        [data-glpi-itildestination-remove-field-config] {
            display: none !important;
        }
    }

    &:has(> [data-glpi-itildestination-field-config]:nth-child(2)) {
        &:has([data-glpi-itildestination-remove-field-config]) {
            [data-glpi-itildestination-field-config] {
                &:not(:has([data-glpi-associated-items-specific-values-extra-field]:not(.d-none))) {
                    .select2-selection {
                        border-top-right-radius: 0 !important;
                        border-bottom-right-radius: 0 !important;
                    }
                }

                &:has([data-glpi-associated-items-specific-values-extra-field]:not(.d-none)) {
                    &:has([data-glpi-itildestination-field-config-display-condition="specific_values"]) {
                        >div {
                            &:first-child {
                                .select2-selection {
                                    border-top-right-radius: 0 !important;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    [data-glpi-itildestination-field-config] {
        display: flex;

        [data-glpi-itildestination-field-config-content] {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: stretch;
            width: 1%; // Small hack to make the select2 dropdown only take the available space

            [data-glpi-itildestination-field-linked-itilobjects-config] {
                >div {
                    &:first-child {
                        width: 30%;

                        .select2-selection {
                            border-top-right-radius: 0 !important;
                            border-bottom-right-radius: 0 !important;
                        }
                    }

                    &:last-child {
                        margin-left: calc(-1 * var(--tblr-border-width));
                        width: calc(70% + 1 * var(--tblr-border-width));

                        .select2-selection {
                            border-top-left-radius: 0 !important;
                            border-bottom-left-radius: 0 !important;
                        }
                    }
                }

                + [data-glpi-itildestination-field-config-display-condition="specific_values"] {
                    > div {
                        display: flex;

                        &:has(> span > span.select2-container) {
                            > span.select2-container  {
                                width: 30% !important;

                                .select2-selection {
                                    border-top-right-radius: 0 !important;
                                    border-bottom-right-radius: 0 !important;
                                }
                            }

                            > br ~ span {
                                margin-left: calc(-1 * var(--tblr-border-width));
                                width: calc(70% + 1 * var(--tblr-border-width));
                            }

                            > span > span.select2-container {
                                .select2-selection {
                                    border-top-left-radius: 0 !important;
                                    border-bottom-left-radius: 0 !important;
                                }
                            }
                        }
                    }
                }
            }

            &:has(div[data-glpi-itildestination-field-config-display-condition]:not(.d-none)) {
                &:not(:has([data-glpi-associated-items-specific-values-extra-field]:not(.d-none))) {
                    >div {
                        &:first-child {
                            .select2-selection {
                                border-bottom-left-radius: 0 !important;
                                border-bottom-right-radius: 0 !important;
                            }
                        }
                    }
                }
            }

            &:not(:has([data-glpi-associated-items-specific-values-extra-field]:not(.d-none))) {
                >div {
                    &[data-glpi-itildestination-field-config-display-condition] {
                        margin-top: calc(-1 * var(--tblr-border-width));

                        .select2-selection {
                            border-top-left-radius: 0 !important;
                            border-top-right-radius: 0 !important;
                        }

                        >div:has(.select2-selection) {
                            &:not(:last-child) {
                                .select2-selection {
                                    border-radius: 0 !important;
                                }
                            }

                            &:not(:first-child) {
                                margin-top: calc(-1 * var(--tblr-border-width));
                            }
                        }
                    }
                }
            }

            // Specific layout for associated items
            &:has([data-glpi-associated-items-specific-values-extra-field]:not(.d-none)) {
                &:has([data-glpi-itildestination-field-config-display-condition="specific_values"]) {
                    >div {
                        &:first-child {
                            .select2-selection {
                                border-bottom-left-radius: 0 !important;
                                border-bottom-right-radius: 0 !important;
                            }
                        }
                    }
                }

                // Make the strategy select fill the whole line
                [data-glpi-associated-items-specific-values-extra-field] {
                    flex-basis: 100%;
                    order: 1;

                    [data-glpi-associated-items-specific-values-extra-field-item] {
                        .select2-selection {
                            border-bottom-right-radius: 0 !important;
                            border-top-left-radius: 0 !important;
                        }

                        &:not(:last-of-type) {
                            .select2-selection {
                                border-bottom-left-radius: 0 !important;
                            }
                        }
                    }
                }

                [data-glpi-associated-items-specific-values-extra-field-item] {
                    margin-top: calc(-1 * var(--tblr-border-width));
                }
            }
        }

        [data-glpi-itildestination-remove-field-config] {
            border-top-left-radius: 0 !important;
            border-bottom-left-radius: 0 !important;
            margin-left: calc(-1 * var(--tblr-border-width));
        }

        [data-glpi-itildestination-remove-field-config],
        [data-glpi-remove-associated-item-button] {
            &:hover {
                z-index: 99;
            }
        }
    }
}

// Hide the condition on creation badge when accordion is expanded
.accordion-button:not(.collapsed) {
    [data-glpi-editor-destination-badges-container] {
        display: none !important;
    }
}

button:has([data-glpi-editor-condition-badge="always_created"].d-flex), button[aria-expanded="true"] {
    [data-glpi-editor-conditions-count-badge] {
        display: none !important;
    }
}

html[data-glpi-theme-dark="1"] {
    span[data-form-tag-value].bg-dark-lt {
        color: color-mix(in srgb, var(--tblr-light) calc(var(--tblr-bg-opacity,1) * 100%),transparent) !important;
        background-color: color-mix(in srgb, var(--tblr-light-lt) calc(var(--tblr-bg-opacity,1) * 100%),transparent) !important;
    }
}
